<?php
class IndexAction extends BaseAction{
	// 首页
	public function index(){
		$totalsell = service('Statistics')->countGoodsSellByPid($_SESSION['qp_id']);
		$this->assign('totalsell', $totalsell);
		$this->display();
	}
	
	public function domodifypwd(){
		$mpwd_opt 		= t($_POST['mpwd_opt']);
		$adminpwd 		= t($_POST['adminpwd']);
		$adminnewpwd 	= t($_POST['adminnewpwd']);
		$checkernewpwd 	= t($_POST['checkernewpwd']);
		
		if( !in_array($mpwd_opt,array('admin','checker','nopwd')) )	$this->error('修改失败，未指定修改类型！');
		if(empty($adminpwd))	$this->error('修改失败，管理员密码为空！');
		if($mpwd_opt=='admin'&&empty($adminnewpwd))	$this->error('修改失败，新管理员密码为空！');
		if($mpwd_opt=='checker'&&empty($checkernewpwd))	$this->error('修改失败，新验证员密码为空！');
	
		$partner = D('Partner','Admin')->selectById($_SESSION['qp_id']);
		
		if(empty($partner)) {
			$this->error('修改失败，店铺不存在！');
		}else{
			if(md5($adminpwd)!=$partner['admin_password']){
				$this->error('修改失败，管理员密码错误！');
			}
		}
		if($mpwd_opt=='admin'){
			if(md5($adminnewpwd)==$partner['admin_password']){
				
			}else{
				$map['id']=$_SESSION['qp_id'];
				$no = M('Partner')->where($map)->setField('admin_password', md5($adminnewpwd));
				if(!$no)$this->error('管理员密码修改失败！');
			}
			$this->success('管理员密码修改成功！新密码：'.$adminnewpwd);
		}
		
		if($mpwd_opt=='checker'){
			if(md5($checkernewpwd)==$partner['checker_password']){
				
			}else{
				$map['id']=$_SESSION['qp_id'];
				$no = M('Partner')->where($map)->setField('checker_password', md5($checkernewpwd));
				if(!$no)$this->error('验证员密码修改失败！');
			}
			$this->success('验证员密码修改成功！新密码：'.$checkernewpwd);
		}
		
		
		if($mpwd_opt=='nopwd'){
			if(empty($partner['checker_password'])){
				
			}else{
				$map['id']=$_SESSION['qp_id'];
				$no = M('Partner')->where($map)->setField('checker_password', '');
				if(!$no)$this->error('验证员密码修改失败！');
			}
			$this->success('验证员设置为无需密码登录！');
		}
		$this->error('修改失败！');
	}
	
	/**
     +----------------------------------------------------------
     * 用户、商户  咨询，报错，问答
     +----------------------------------------------------------
     * @access protected
     +----------------------------------------------------------
     * @param string $message 提示信息
     * @param Boolean $ajax 是否为Ajax方式
     +----------------------------------------------------------
     * @return void
     +----------------------------------------------------------
     */
    public function advisory(){
    	$dialogueData['surl']=U('shanghu://Index/submitadvisory');//提交url
    	$dialogueData['advisorytype']='suggest';//咨询分类 suggest error question
    	$dialogueData['showtype']=array('suggest','error','question');//咨询分类 suggest error question 在tab中显示哪些
    	$this->assign('dialogueData', $dialogueData);
    	$this->display(SITE_PATH.'/Public/advisory.html');
    }
    
	public function submitadvisory(){
		$qtext = h($_POST['qtext']);
		$opttype = t($_POST['opttype']);
		if( strlen($qtext) > 110 ){
			exit(json_encode(array('status'=>-1,'msg'=>'内容长度需小于100字符！')));
		}
		if( !in_array($opttype,array('suggest','error','question') ) ){
			exit(json_encode(array('status'=>-1,'msg'=>'请选择类型')));
		}
		$id = service('Common')->submitDialogue($_SESSION['qp_id'],'shanghu',$opttype,$qtext);
		if($id){
			exit(json_encode(array('status'=>1,'msg'=>'提交成功！将尽快处理！')));
		}else{
			exit(json_encode(array('status'=>0,'msg'=>'提交失败！')));
		}
	}
	
	/**
	 * 确认消费前的查询
	 
	public function searchCoupon(){
		$passcode = $_POST['codevalue'];
		if(empty($passcode))exit(json_encode(array('status'=>-1,'msg'=>'请录入'.K('SP_COUPON_NM').'码！')));
		$result = service('Shanghu')->checkPassCode($passcode);
		exit(json_encode($result));
	}
	
	// 商户礼券验证
	public function check(){
		$this->display();
	}
	*/
	
	/**
	 * 确认礼券被使用
	 
	public function confirmCoupon(){
		$passcode = $_POST['codevalue'];
		if(empty($passcode))exit(json_encode(array('status'=>-1,'msg'=>'请录入'.K('SP_COUPON_NM').'码！')));
		$result = service('Shanghu')->doConfirmCoupon($passcode);
		exit(json_encode($result));
	}
	
	
	public function ajxSearchProduct(){
		$pid = $_SESSION['qp_parent_id'];
		if(empty($pid))$pid='-';
		$map['partner_id']=$pid;
		$map['is_delete']='N';
		$pagedata = D('Goods','Admin')->selectAllByPage($map, 10);
		//dump($pagedata);
		$xml = $this->_parse2Xml4Table($pagedata['data'],$pagedata['nowPage'],$pagedata['totalPages']);
		exit($xml);
	}
	*/
	
	/**
	public function ajxstatgoods(){
		$pid = $_SESSION['qp_parent_id'];
		$gid = $_REQUEST['gid'];
		$stattype = $_REQUEST['stattype'];
		//echo $gid."|".$stattype;
		Log::record('ajxstatsell 当前parentid='.$pid,Log::DEBUG,Log::FILE);
		Log::save(); 
		if(empty($pid))$pid='-';
		$statdata = service('Statistics')->statGoods4Checked(array('pid'=>$pid,'gid'=>$gid,'rtntype'=>'chart','stattype'=>$stattype),'down',false,6);
		
		exit(json_encode( array('status'=>'1','data'=>$statdata) ));
	}
	
	public function ajxstatshangh(){
		$pid = $_SESSION['qp_parent_id'];
		Log::record('ajxstatsell 当前parentid='.$pid,Log::DEBUG,Log::FILE);
		Log::save(); 
		if(empty($pid))$pid='-';
		$statdata = service('Statistics')->statPartner4Checked(array('pid'=>$pid,'rtntype'=>'chart','stattype'=>'time'),'down',false,6);
		
		exit(json_encode( array('status'=>'1','data'=>$statdata) ));
	}
	**/
	
	
	
	/**
	 * 将商品数据转换为XML格式(flexigrid支持的格式)
	
	private function _parse2Xml4Table($data,$page,$total){
		header("Expires: Mon, 26 Jul 2011 05:00:00 GMT" );
		header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
		header("Cache-Control: no-cache, must-revalidate" );
		header("Pragma: no-cache" );
		header("Content-type: text/xml");
		$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
		$xml .= "<rows>";
		$xml .= "<page>$page</page>";
		$xml .= "<total>$total</total>";
		foreach($data as $vo){
			$xml .= "<row id='".$vo['id']."'>";
			$xml .= "<cell><![CDATA[".$vo['title']."]]></cell>";
			$xml .= "<cell><![CDATA[".getCategoryName($vo['sort_id'])."]]></cell>";
			$xml .= "<cell><![CDATA[".formatMoney('11')."]]></cell>";
			$xml .= "<cell><![CDATA[".$vo['send_number']."]]></cell>";
			$xml .= "</row>";
		}
		$xml .= "</rows>";
		return $xml;
	}
	 */
}

?>